// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;

namespace SnapObjects.Data
{
    internal class ConditionStatement : SqlBuildStatement
    {
        public ConditionStatement(SqlConditionType conditionType, bool isEmbedded)
        {
            this.IsEmbedded = isEmbedded;
            this.ConditionType = conditionType;
            this.Condition = new SqlBuildClause(this.OnChanged);
        }

        public override SqlStatementType StatementType => SqlStatementType.Condition;

        public SqlConditionType ConditionType { get; }

        public SqlBuildClause Condition { get; private set; }

        public bool IsEmbedded { get; }

        public override SqlBuildStatement Clone()
        {
            var condition = new ConditionStatement(this.ConditionType, this.IsEmbedded)
            {
                _nameGenerator = new ParameterNameGenerator(_nameGenerator.Count),
                _parameters = new Dictionary<string, ISqlBuilderParameter>(_parameters, StringComparer.OrdinalIgnoreCase)
            };

            condition.Condition = condition.Condition.Clone(condition.OnChanged);

            return condition;
        }
    }
}
